10a11,12
> static Lock SizeTableLock;
> 
42a45
>    LockAcquire(&SizeTableLock);
49a53
> 	       LockRelease(&SizeTableLock);
51a56
> 	       LockRelease(&SizeTableLock);
68a74,75
> 
>    LockRelease(&SizeTableLock);
79a87
>    LockAcquire(&SizeTableLock);
90c98,99
<             free(HashLink);
---
>             shfree(HashLink);
> 	    LockRelease(&SizeTableLock);
95a105
>       LockRelease(&SizeTableLock);
97a108
>       LockRelease(&SizeTableLock);
110a122
>    LockAcquire(&SizeTableLock);
119a132
> 	       LockRelease(&SizeTableLock);
124a138
>       LockRelease(&SizeTableLock);
126a141
>       LockRelease(&SizeTableLock);
138a154
>    LockAcquire(&SizeTableLock);
143a160
> 	    LockRelease(&SizeTableLock);
147a165
>       LockRelease(&SizeTableLock);
151a170
>       LockRelease(&SizeTableLock);
181a201
>    LockInit(&SizeTableLock, "SizeTableLock");
190c210,211
<    
---
> 
>    LockAcquire(&SizeTableLock);
196,197c217
< 	    
< 	    free(HashLink->addr);
---
> 	    shfree(HashLink->addr);
199c219
< 	    free(HashLink);
---
> 	    shfree(HashLink);
204c224
< 
---
>    LockRelease(&SizeTableLock);
207c227,228
< #endif 
---
> #endif /* _C2_DBGR_ */
> 
8a9,10
> #include <stdio.h>
> 
26a29,30
>    LockAcquire(&(m->AddrMapLock));
> 
34a39
>       LockRelease(&(m->AddrMapLock));
51a57
>    LockRelease(&(m->AddrMapLock));
64a71
> 
70a78
>   LockInit(&(tmpMap->AddrMapLock));
74c82
<   _c2_allocDbgGph(tmp);		/* allocate a struct in tmp for debugging */
---
>   _c2_allocDbgGph(tmp);
75a84
> 
91a101,103
> 
>   printf ("makenode (c2_addrmap.c) making a %d\n", UID);
> 
92a105,108
>   printf ("makenode (c2_addrmap.c) making a %d\n", UID);
>    LockInit(&(tmpN->DataLock));
>    LockInit(&(tmpN->QueueLock));
>   printf ("makenode (c2_addrmap.c) making a %d\n", UID);
99a116
>    tmpN->HeadLock = tmpN->NextLock = (_c2_LockSet *) 0;
102,103c119,120
<    tmpN->HeadLock = tmpN->NextLock = (_c2_LockSet *) 0;
<    if (Crepped) 
---
>    if (Crepped) {
>      printf ("makenode (c2_addrmap.c) making a %d\n", UID);
104a122,123
>      printf ("makenode (c2_addrmap.c) making a %d\n", UID);
>    }
106c125
<    _c2_allocDbgUc(tmpN);	/* allocate a struct in tmpN for debugging */
---
>    _c2_allocDbgUc(tmpN);
123a143
>    LockInit(&(tmpN->QueueLock));
136a157
> 
151,153c172,175
< #  ifdef _C2_DBGR_
<       _c2_dbgGphCreatAction(g, fplist);
< #  endif
---
> #ifdef _C2_DBGR_
>    _c2_dbgGphCreatAction(g, fplist);
> #endif
> 
164,166c186
< #           ifdef DEBUG	    
< 	       printf("initing a uc %d\n", u->UID);
< #           endif
---
> 	    printf("initing a uc %d\n", u->UID);
174,176c194
< #           ifdef DEBUG
< 	       printf("initing nsrel %d\n", u->UID);
< #           endif
---
> 	    printf("initing nsrel %d\n", u->UID);
187,232c205
<   /* Add NS lock to sorted list of locks.  Sort by UID of shared var
<      in NSRel.  This allows detection of use of two instances of same
<      shared var  */
< 
< void _c2_InsertLock(HeadLock, NewLock)
<    _c2_LockSet **HeadLock;
<    _c2_LockSet *NewLock;
< {
<    _c2_LockSet *cur;
<    _c2_LockSet *prev;
< 
<    /* Find link that new one must come before */
< 
<    cur = *HeadLock;
<    while (cur != 0) {
< 
<       if (NewLock->UID == cur->UID)
< 	 fprintf(stderr, "\n ****** Warning: %s\n         %s\n\n",
< 		 "Attempt to use two instances of the same shared variable", 
<                  "from the same UC innstance.  This is illegal!!!");
< 
<       if (NewLock->UID < cur->UID) break;
<       prev = cur;
<       cur = cur->Next;
<    }
< 
<    if (*HeadLock == 0) {  /* NewLock is first to go into List */
<       *HeadLock = NewLock;
<       NewLock->Next = 0;
<    } else if (cur == *HeadLock) {  /* New first in non-empty list */
<       NewLock->Next = cur;
<       *HeadLock = NewLock;
<    } else { 
<       NewLock->Next = cur;
<       prev->Next = NewLock;
<    }
< }
< #ifdef _C2_DBGR_
< 
<   /* Add node to list of those waiting for lock
<    * This is similar to the one for sequent. Interactive
<    * debugging may introduce non-determinism in this serial  implementation.
<    * Note that we may stop a UC before computation, and let the others
<    * run. This may cause other UC's to acquire shared access in an order
<    * that is different from the one recorded, causing the replay to fail.
<    */
---
>   /* Add node to list of those waiting for lock */
275c248
<       free(Tmp);
---
>       shfree(Tmp);
281d253
< #endif /* _C2_DBGR_ */
283c255,372
<   /* copy value of all shared variables into local space */
---
>   /* Get an NSRel read or write lock */
> #ifdef _C2_DBGR_
> int _c2_GetLock(psplist, NSRelAddr, RCount, RQ, WCount, WQ, ReqType, UCAddr)
>    _c2_List *psplist;
> #else
> int _c2_GetLock(NSRelAddr, RCount, RQ, WCount, WQ, ReqType, UCAddr)
> #endif
>    _c2_NSRelBase *NSRelAddr;
>    int *RCount;                 /* Count of active readers */
>    _c2_NSLink **RQ;             /* Reader wannabes */
>    int *WCount;                 /* Count of active writers (0 or 1) */
>    _c2_NSLink **WQ;             /* Writer wannabes */
>    int ReqType;
>    _c2_NodeBase *UCAddr;
> {
>    int GotIt;
> 
>    LockAcquire(&(NSRelAddr->QueueLock));
> 
>    /* There are three cases: there are active readers, writers, or neither */
> 
>    if (*RCount > 0) {   /* Active readers */
> 
>       if (ReqType == _c2_READER) {
> 	 /* Allow another reader if no writers queued */
> 	 if ((*WQ == 0)
> #ifdef _C2_DBGR_
> 	    &&  !_c2_readSpBpAct(UCAddr, psplist, 0)
> #endif
> 	     ) {
> 	    *RCount += 1;
> 	    GotIt = 1;
> 	 } else {
> 	    _c2_AddToNSQ(UCAddr, RQ);
> 	    GotIt = 0;
> 	 }
>       } else { /* Write request */
> 	 /* Always Q it. */
> 	 _c2_AddToNSQ(UCAddr, WQ);
> 	 GotIt = 0;
>       }
> 
>    } else if (*WCount > 0) { /* Active writers */
> 
>       if (ReqType == _c2_READER) {
> 	 /* Always Q it. */
> 	 _c2_AddToNSQ(UCAddr, RQ);
> 	 GotIt = 0;
>       } else { /* Write request */
> 	 /* Always Q it. */
> 	 _c2_AddToNSQ(UCAddr, WQ);
> 	 GotIt = 0;
>       }
> 
>    } else { /* No current readers or writers */
> 
> #ifdef _C2_DBGR_
>       if (!_c2_readSpBpAct(UCAddr, psplist, ReqType == _c2_WRITER)) { 
> #endif
> 	 if (ReqType == _c2_READER) {
> 	    *RCount += 1;
> 	    GotIt = 1;
> 	 } else { /* Write request */
> 	    *WCount += 1;
> 	    GotIt = 1;
> 	 }
> #ifdef _C2_DBGR_
>       } else {			/* only here in the replay mode */
> 	 GotIt = 0; 
> 	 if (ReqType == _c2_READER) {
> 	    _c2_AddToNSQ(UCAddr, RQ); 
> 	    _c2_ClearNSQ(WQ);
> 	 } else {
> 	    if (*WQ != 0) _c2_ClearNSQ(WQ); /* a writer can be waiting for a */
> 	    if (*RQ != 0) _c2_ClearNSQ(RQ); /* reader/writer in the replay mode */
> 	    _c2_AddToNSQ(UCAddr, WQ); 
> 	 }
>       }
> #endif
>    }
> 
>    LockRelease(&(NSRelAddr->QueueLock));
>    return GotIt;
> }
> 
> 
>   /* Release an NSRel read or write lock */
> 
> void _c2_RelLock(NSRelAddr, RCount, RQ, WCount, WQ, ReqType)
>    _c2_NSRelBase *NSRelAddr;
>    int *RCount;                 /* Count of active readers */
>    _c2_NSLink **RQ;             /* Reader wannabes */
>    int *WCount;                 /* Count of active writers (0 or 1) */
>    _c2_NSLink **WQ;             /* Writer wannabes */
>    int ReqType;
> {
> 
>    LockAcquire(&(NSRelAddr->QueueLock));
> 
>    if (ReqType == _c2_READER) {
> 
>       *RCount -= 1;
>       if (*RCount == 0)  _c2_ClearNSQ(WQ);
> 
>    } else { /* Write request */
>  
>       *WCount -= 1;
>       if (*WQ != 0) _c2_ClearNSQ(WQ);
>       else _c2_ClearNSQ(RQ);
> 
>    }
> 
>    LockRelease(&(NSRelAddr->QueueLock));
> }
> 
> 
>   /* Add NS lock to *sorted* list of locks.  Sort by UID of shared var
>      in NSRel.  This avoids deadlock. */
285c374,414
< int  _c2_GetAllLocks(_c2_na, NextLock)
---
> void _c2_InsertLock(HeadLock, NewLock)
>    _c2_LockSet **HeadLock;
>    _c2_LockSet *NewLock;
> {
>    _c2_LockSet *cur;
>    _c2_LockSet *prev;
> 
>    /* Find link that new one must come before */
> 
>    cur = *HeadLock;
>    while (cur != 0) {
> 
>       if (NewLock->UID == cur->UID)
> 	 fprintf(stderr, "\n ****** Warning: %s\n         %s\n\n",
> 		 "Attempt to use two instances of the same shared variable", 
>                  "from the same UC innstance.  This is illegal!!!");
> 
>       if (NewLock->UID < cur->UID) break;
>       prev = cur;
>       cur = cur->Next;
>    }
> 
>    if (*HeadLock == 0) {  /* NewLock is first to go into List */
>       *HeadLock = NewLock;
>       NewLock->Next = 0;
>    } else if (cur == *HeadLock) {  /* New first in non-empty list */
>       NewLock->Next = cur;
>       *HeadLock = NewLock;
>    } else { 
>       NewLock->Next = cur;
>       prev->Next = NewLock;
>    }
> }
> 
> 
>   /* Acquire all locks in list from NextLock to end.  If fail to get a
>      lock, leave NextLock pointing at it to try again next time.
>      Return 1 if reach end of list (all locks acquired), return 0 if
>      fail to get one-- hence more locks needed */
> 
> int _c2_GetAllLocks(_c2_na, NextLock)
294,317c423,447
< 
< #     ifdef _C2_DBGR_
<       if (_c2_readSpBpAct(_c2_na, cur->psplist,
< 				(cur->ReqType == _c2_WRITER))) { 
< 	 _c2_AddToNSQ(_c2_na, cur->Q);
< 	 warning("non-determinism detected; didn't find the desired shared pred");
< 	 return 0;
<       }
< 	  
< #    endif
<       switch (cur->TypeTag) {
<        case _c2_IsAnInt:
< 	 *((int *)(cur->LocalAddr)) = *((int *)(cur->SharedAddr));
< 	 break;
<        case  _c2_IsADouble:
< 	 *((double *)(cur->LocalAddr)) = *((double *)(cur->SharedAddr));
< 	 break;
<        case _c2_IsAnArrayPtr:
<        case _c2_IsAStructPtr:
< 	 *((void **)(cur->LocalAddr)) = *((void **)(cur->SharedAddr));
< 	 break;
<        case _c2_IsAChar:
< 	 *((char *)(cur->LocalAddr)) = *((char *)(cur->SharedAddr));
< 	 break;
---
> #ifdef _C2_DBGR_
>       if (_c2_GetLock(cur->psplist, cur->NSRelAddr, cur->RCount, cur->RQ,
> 		      cur->WCount, cur->WQ, cur->ReqType, _c2_na)) {
> #else
>     if (_c2_GetLock(cur->NSRelAddr, cur->RCount, cur->RQ,
> 		      cur->WCount, cur->WQ, cur->ReqType, _c2_na)) {
> #endif
> 	 switch (cur->TypeTag) {
> 	  case _c2_IsAnInt:
> 	    *((int *)(cur->LocalAddr)) = *((int *)(cur->SharedAddr));
> 	    break;
> 	  case  _c2_IsADouble:
> 	    *((double *)(cur->LocalAddr)) = *((double *)(cur->SharedAddr));
> 	    break;
> 	  case _c2_IsAnArrayPtr:
> 	  case _c2_IsAStructPtr:
> 	    *((void **)(cur->LocalAddr)) = *((void **)(cur->SharedAddr));
> 	    break;
> 	  case _c2_IsAChar:
> 	    *((char *)(cur->LocalAddr)) = *((char *)(cur->SharedAddr));
> 	    break;
> 	 }
>       } else {
> 	 *NextLock = cur;
> 	 return 0;   /* Failed to get this lock */
318a449
> 
320a452
> 
322d453
< }
323a455
> }
325d456
<   /* copy local value of shared vars back to nsrel node */
326a458
>   /* Release a list of locks, resetting the next lock pointer */ 
328c460
< void _c2_RelAllLocks(na, HeadLock, NextLock)
---
>    void _c2_RelAllLocks(na, HeadLock, NextLock)
331c463
< void _c2_RelAllLocks(HeadLock, NextLock)
---
>    void _c2_RelAllLocks(HeadLock, NextLock)
334a467
> 
353,362c486,491
< #     ifdef _C2_DBGR_
<       if  (cur->ReqType == _c2_WRITER) {
< 	 _c2_writeSpBpAct(na, cur->psplist);
<       }
<       if (*(cur->Q) != 0) {
< 	    _c2_ClearNSQ(cur->Q);
< 	    warning("nondeterminism resolved\n");
< 	 }
< #     endif
< 
---
> #ifdef _C2_DBGR_
>       if (cur->ReqType == _c2_WRITER) 
> 	  _c2_writeSpBpAct(na, cur->psplist);
> #endif
>       _c2_RelLock(cur->NSRelAddr, cur->RCount, cur->RQ, cur->WCount, cur->WQ,
> 		  cur->ReqType);
367a497,498
> 
> 
4a5
> 
6a8
> 
30a33
>    Lock AddrMapLock; /* Lock address map before use */
70a74,84
>   /* Acquire all locks in list from NextLock to end.  If fail to get a
>      lock, leave NextLock pointing at it to try again next time.
>      Return 1 if reach end of list (all locks acquired), return 0 if
>      fail to get one-- hence more locks needed */
> 
> int _c2_GetAllLocks( /* _c2_NodeBase * _c2_na, _c2_LockSet **NextLock */ );
> 
>   /* Release a list of locks, resetting the next lock pointer */
> 
> void _c2_RelAllLocks( /* _c2_LockSet **HeadLock, _c2_LockSet **NextLock */ );
> 
75,76c89,100
< int _c2_GetAllLocks( /* _c2_NodeBase * _c2_na, _c2_LockSet **NextLock */ );
< void _c2_RelAllLocks( /* _c2_LockSet **HeadLock, _c2_LockSet **NextLock */ );
---
> 
>   /* Get an NSRel read or write lock */
> 
> int _c2_GetLock( /* _c2_NSRelBase *NSRelAddr, int *RCount, _c2_NSLink **RQ,
>                     int *WCount, _c2_NSLink **WQ, int ReqType,
>                     _c2_NodeBase *UCAddr */ );
> 
>   /* Release an NSRel read or write lock */
> 
> void _c2_RelLock( /* _c2_NSRelBase *NSRelAddr, int *RCount, _c2_NSLink **RQ,
>                      int *WCount, _c2_NSLink **WQ, int ReqType */ );
> 
3,4d2
< extern char *malloc( /* unsigned size */ );
< 
10c8
<    tmp = malloc(size);
---
>    tmp = (char *) malloc(size);
10a11,12
> #include "fthread.h"
> #include "fsynch.h"
12a15
> 
14,15c17,18
< #include <c2_udbg_intrf.h>		/* debugger's decl */
< #endif 
---
> #include <c2_udbg_intrf.h>
> #endif
17d19
<   /* Things that we should not need but do */
19c21
< extern char *_c2_shmalloc( /* unsigned size */ );
---
>   /* Things that we should not need but do */
20a23,24
> extern char *_c2_shmalloc( unsigned size );
> #define shfree free
46a51,55
>    int *RCount;
>    _c2_NSLink **RQ;
>    int *WCount;
>    _c2_NSLink **WQ;
>    int ReqType;
50a60
>    int UID;
52d61
<    _c2_NSLink **Q;		/* provision for replay during interactive debugging */
54d62
<    int ReqType;
56d63
<    int UID;
61a69,70
>    Lock DataLock;
>    Lock QueueLock;
78d86
< 
104a113
>    Lock QueueLock;
143,144d151
<   /* keep track of amount of space allocated on heap */
< unsigned _c2_totalloc;
146c153,156
< #ifdef _c2_DBGR_
---
> /* for debugger restarting the execution,  we need to deallocate all the */
>  /* LocalData objects in various structs. This is the fastest and the */
>  /* easiest way of doing it. see cmddbgr.h for rationale */
> #ifdef _C2_DBGR_
148c158
< #endif
---
> #endif 
150d159
< #endif
151a161,164
>   /* keep track of amount of space allocated on heap */
> unsigned _c2_totalloc;
> 
> #endif
2a3,4
> #include <stdio.h>
> 
5c7
< _c2_SeqVarQ Q;
---
>     _c2_SeqVarQ Q;
10c12
< }
---
> };
24c26
<             free(FreeSeqVar); 
---
>             shfree(FreeSeqVar); 
57c59
<  * are being checked/removed. This address and the list appended to the value
---
>  * are being checked. This address and the list appended to the value
61c63
<  * predecessor id inside the _c2_NodeBase struct 
---
>  * predecessor id inside the _c2_NodeBase struct
68,86d69
< #ifdef _C2_DBGR_
< int _c2_Check(nodeaddr, Q, I) 
<     _c2_NodeBase * nodeaddr;
< #else
< int _c2_Check(Q, I)
< #endif
<      _c2_SeqVarQ Q; 
<      _c2_Index *I;
< {
<     _c2_SeqVar *ThisSeqVar;
<     int i;
< 
<     ThisSeqVar = Q[I->NumInd];
<     if (I->NumInd > 0) {
<        while (ThisSeqVar != ((_c2_SeqVar *)0)) {
< #         ifdef _C2_DBGR_
< 	  if (_c2_chkFpBpAct(nodeaddr, ThisSeqVar->value.fplist))
< #         endif
< 	      {
88,183c71,72
< 		 for (i=0; i<I->NumInd; i++) {
< 		    if (ThisSeqVar->index.Ind[i] == I->Ind[i]) {
< 		       if (i == I->NumInd - 1) return 1;
< 		    } else
< 			break;
< 		 }
< 	      }
< 	  ThisSeqVar = ThisSeqVar->next;
<        }
<        return 0;
<     } else {
<        while (ThisSeqVar != ((_c2_SeqVar *)0)) { 
< #          ifdef _C2_DBGR_	/* not reached when undefined */
< 	   if (_c2_chkFpBpAct(nodeaddr, ThisSeqVar->value.fplist)) 
< #          endif 
< 	       {
< 		  return 1;
< 	       }
< #          ifdef _C2_DBGR_
< 	   ThisSeqVar = ThisSeqVar->next; /* Here only in dbg replay mode */
< #          endif
< 	} 
<        return 0;
<     }
< };
< 
< #ifdef _C2_DBGR_
< int 
< _c2_Remove(nodeaddr, Q, I, V) 
<     _c2_NodeBase * nodeaddr;
< #else
< int _c2_Remove(Q, I, V)
< #endif
<     _c2_SeqVarQ Q; 
<     _c2_Index *I;
<     _c2_Value *V;
< {
<    _c2_SeqVar *ThisSeqVar, *PrevSeqVar;
<    int i;
< 
<    PrevSeqVar = ((_c2_SeqVar *)0);
< 
<    ThisSeqVar = Q[I->NumInd];
<    if (I->NumInd > 0) {
<       while (ThisSeqVar != ((_c2_SeqVar *)0)) {
< #        ifdef _C2_DBGR_
< 	 if (_c2_chkFpBpAct(nodeaddr, ThisSeqVar->value.fplist)) 
< #        endif
< 	     {
< 		for (i=0; i<I->NumInd; i++) {
< 		   if (ThisSeqVar->index.Ind[i] == I->Ind[i]) {
< 		      if (i == I->NumInd - 1) {
< 			 *V = ThisSeqVar->value; 
< 			 if (PrevSeqVar != ((_c2_SeqVar *)0))
< 			     PrevSeqVar->next = ThisSeqVar->next;
< 			 else 
< 			     Q[I->NumInd] = Q[I->NumInd]->next;
< 			 free(ThisSeqVar);
< 			 return 1;
< 		      }
< 		   } else
< 		       break;
< 		}
< 	     }
< 	 PrevSeqVar = ThisSeqVar;
< 	 ThisSeqVar = ThisSeqVar->next;
<       }
<       return 0;
<    } else {
<       while (ThisSeqVar != ((_c2_SeqVar *)0)) {
< #        ifdef _C2_DBGR_
< 	 if (_c2_chkFpBpAct(nodeaddr, ThisSeqVar->value.fplist))
< #        endif
< 	     {
< 		*V = ThisSeqVar->value; 
< 		if (PrevSeqVar != ((_c2_SeqVar *) 0) )
< 		    PrevSeqVar->next = ThisSeqVar->next;
< 		else 
< 		    Q[I->NumInd] = Q[I->NumInd]->next;
< 		free(ThisSeqVar);
< 		return 1;
< 	     }
< #        ifdef _C2_DBGR_
< 	 PrevSeqVar = ThisSeqVar;
< 	 ThisSeqVar = ThisSeqVar->next; /* Here only in debugger replay mode */
< #        endif
<       }
<       return 0;
<    }
< }
< 
< 
< 
< 
< /* routines without the debugger code. Only here to make the above more 
<    understandable.
---
> /* Following two routines without the preprocessor #ifdef for the debugger
>    instrumentation to facilitate the understanding.
212d100
< 
235c123
<                         free(ThisSeqVar);
---
>                         shfree(ThisSeqVar);
249c137
<             free(ThisSeqVar);
---
>             shfree(ThisSeqVar);
256c144,260
< */
---
> abvoe two routines commented out */
> 
> #ifdef _C2_DBGR_
> int 
> _c2_Check(nodeaddr, Q, I) 
>     _c2_NodeBase * nodeaddr;
> #else
> int _c2_Check(Q, I)
> #endif
>      _c2_SeqVarQ Q; 
>      _c2_Index *I;
> 
> {
>     _c2_SeqVar *ThisSeqVar;
>     int i;
> 
>     ThisSeqVar = Q[I->NumInd];
>     if (I->NumInd > 0) {
>        while (ThisSeqVar != ((_c2_SeqVar *)0)) {
> #         ifdef _C2_DBGR_
>           if ( _c2_chkFpBpAct(nodeaddr, ThisSeqVar->value.fplist)) 
> #         endif
>               {
>                  for (i=0; i<I->NumInd; i++) {
>                     if (ThisSeqVar->index.Ind[i] == I->Ind[i]) {
>                        if (i == I->NumInd - 1) return 1;
>                     } else
>                         break;
>                  }
>               }
> 	  ThisSeqVar = ThisSeqVar->next;
>        }
>        return 0;
>     } else {
>        while (ThisSeqVar != ((_c2_SeqVar *)0)) {
> #          ifdef _C2_DBGR_
>            if  (_c2_chkFpBpAct(nodeaddr, ThisSeqVar->value.fplist)) 
> #          endif
> 	       {
> 		  return 1;
> 	       }
> #          ifdef _C2_DBGR_
> 	   ThisSeqVar = ThisSeqVar->next; /* Only for dbgr replay mode */
> #          endif
> 	} 
>        return 0;
>     }
>  };
> 
> 
> #ifdef _C2_DBGR_
> int _c2_Remove(nodeaddr, Q, I, V) 
>     _c2_NodeBase * nodeaddr;
> #else
> int _c2_Remove(Q, I, V)
> #endif
>     _c2_SeqVarQ Q; 
>     _c2_Index *I;
>     _c2_Value *V;
> 
> {
>    _c2_SeqVar *ThisSeqVar, *PrevSeqVar;
>    int i;
> 
>    PrevSeqVar = ((_c2_SeqVar *)0);
> 
>    ThisSeqVar = Q[I->NumInd];
>    if (I->NumInd > 0) {
>       while (ThisSeqVar != ((_c2_SeqVar *)0)) {
> #        ifdef _C2_DBGR_
>          if (_c2_chkFpBpAct(nodeaddr, ThisSeqVar->value.fplist)) 
>              {
> #        endif 
>                 for (i=0; i<I->NumInd; i++) {
>                    if (ThisSeqVar->index.Ind[i] == I->Ind[i]) {
>                       if (i == I->NumInd - 1) {
>                          *V = ThisSeqVar->value; 
>                          if (PrevSeqVar != ((_c2_SeqVar *)0))
>                              PrevSeqVar->next = ThisSeqVar->next;
>                          else 
>                              Q[I->NumInd] = Q[I->NumInd]->next;
>                          shfree(ThisSeqVar);
>                          return 1;
>                       }
>                    } else
>                        break;
>                 }
> #            ifdef _C2_DBGR_
>              }
> #            endif
>          PrevSeqVar = ThisSeqVar;
>          ThisSeqVar = ThisSeqVar->next;
>       }
>       return 0;
>    } else {
>       while  (ThisSeqVar != ((_c2_SeqVar *)0)) {
> #        ifdef _C2_DBGR_
>          if (_c2_chkFpBpAct(nodeaddr, ThisSeqVar->value.fplist)) 
> #        endif
> 	     {
> 		*V = ThisSeqVar->value; 
> 		if (PrevSeqVar != ((_c2_SeqVar *) 0) )
> 		    PrevSeqVar->next = ThisSeqVar->next;
> 		else 
> 		    Q[I->NumInd] = Q[I->NumInd]->next; /* normal operation */
> 		shfree(ThisSeqVar);
> 		return 1;
> 	     }
> #        ifdef _C2_DBGR_
> 	 PrevSeqVar = ThisSeqVar; /* only for debugger replay mode */
> 	 ThisSeqVar = ThisSeqVar->next; 
> #        endif
>       } 
>       return 0;
>    }
> }
> 
261c265
<    struct _c2_Cache *c;
---
> struct _c2_Cache *c;
263,264c267,273
<    c->Current = 0;
<    c->Len = 0;
---
>   printf ("_c2_CacheInit enter\n");
>   /*  c = (struct _c2_Cache *) _c2_shmalloc(sizeof(struct _c2_Cache)); /* this line is mine */
>   printf ("Hey, ok...");
>   c->Current = 0;
>   printf ("_c2_CacheInit.1\n");
>   c->Len = 0;
>   printf ("_c2_CacheInit depart\n");
5a6
> 
22c23
< #   ifdef _C2_DBGR_
---
> #ifdef _C2_DBGR_
25c26
< #   endif
---
> #endif
2a3,6
> 
> #define DEBUG
> 
> 
7a12,14
> #include <setjmp.h>
> #include <signal.h>
> #include <errno.h>
11c18
< int _c2_Terminated;  /* 1 iff term node has fired */
---
> /* static */ int _c2_Terminated;  /* 1 iff term node has fired */
13c20
<    /* structure for links in  ready Q-- actually LIFO */
---
>    /* structure for links in shared ready Q-- actually LIFO */
20,21c27,32
< static  _c2_RQLink *Head;
< static  _c2_RQLink *FreeList;
---
> static _c2_RQLink *Head;
> static _c2_RQLink *FreeList;
> static Lock RQLock;
> 
> static Thread *WorkerList[MAXWORKERS];
> 
66a78
>    LockAcquire(&(NodeToAdd->QueueLock));
68a81
>       LockRelease(&(NodeToAdd->QueueLock));
77a91
>       LockRelease(&(NodeToAdd->QueueLock));
80a95
>       LockRelease(&(NodeToAdd->QueueLock));
82a98
> 
84,85c100,101
<     case _c2_ONDBGQ: /* debugger will later run it */
< #   endif
---
>     case _c2_ONDBGQ:		/* Debugger will later put it for running */
> #   endif 
87a104
>       LockRelease(&(NodeToAdd->QueueLock));
93a111
>       LockRelease(&(NodeToAdd->QueueLock));
98a117
>    LockAcquire(&RQLock);
107c126
< 
---
>    LockRelease(&RQLock);
118a138
>    LockAcquire(&RQLock);
120a141
>       LockRelease(&RQLock);
130a152,155
>    LockRelease(&RQLock);
> 
>    LockAcquire(&(ReturnTask->QueueLock));
> 
133a159
>       LockRelease(&(ReturnTask->QueueLock));
138a165
>       LockRelease(&(ReturnTask->QueueLock));
145a173,267
>    /* Just waste some time-- don't hog lock */
> 
> static void _c2_spin(n)
>    int n;
> {
>    int i;
>    for (i = 0; i < n; i++);
> }
> 
> #ifdef _C2_DBGR_
> 
> 
> void _c2_emptyRdyQ()
> {
>    while(_c2_PopNode())
>        ;
> }
> 
> static struct {
>    jmp_buf env;			/* map environment with pid of processes */
>    int pid;			/* pid of the process running the workertasks */
> } WrkrEnv[MAXWORKERS];
> 
> /* signal handler */
> 
> void _c2_inthandler(sig)
> int sig;
> {
>    int i;
>    int pid;
> 
>    pid =getpid();
>    for (i=0; i < numProcessors; i++){        
>       if (WrkrEnv[i].pid == pid) {
> 	 if (sig != _c2_ERRSIGNAL) { /* not debugger code's error */
> 	    psignal("caught", sig);
> 	    if (_c2_debugsignals) {
> 	       fprintf(stderr, "interrupt caught by pid = %d.\n", pid); 
> 	    }
> 	 }
> 	 _c2_setGlobalState(_c2_STOPPED);
> 	 _c2_emptyRdyQ();
> 	 longjmp(WrkrEnv[i].env, 1);
>       }
>    }
>    _c2_reinitWrkrs();
> }
> 
> /* 
>  * To handle the child. Specifically for SIGSEGV that can not be
>  * handled because its handler messes up the shbrk() and shmalloc()
>  */
> 
> #include <sys/wait.h>
> 
> void _c2_ChldHndler()
> {
>    int pid;
>    union wait *status;
> 
>    pid = wait3(status, WNOHANG);
>    if (pid == 0) {
>       error("Why a SIGCHLD");
>    } else {
>       _c2_setGlobalState(_c2_STOPPED);
>       if (status->w_termsig == SIGSEGV) {
> 	 psignal("A worker died", status->w_termsig);
>       } else {
> 	 psignal("detected", status->w_termsig);
>       } 
>       fflush(stdout);
>    }
> }
> 
> 
> /* in case of abnormal abort, the debugger must exist gracefully */
> 
> void _c2_KillWorkers()
> {
>    int i;
>    _c2_StopAll();
>    /* 
>     * in case some processes are stalled and can not
>     * terminate normally, do it the hard way!
>     */
>    for (i=0; i<numProcessors; i++){
>       if (_c2_debugsignals)
> 	  printf("killing worker %d\n", WrkrEnv[i].pid);
>       kill(WrkrEnv[i].pid, SIGKILL);
>    }
> }   
> #endif /* _C2_DBGR_ */
> 
> 
> 
149,150c271,273
<  void _c2_WorkerTask(ID)
<    int ID;
---
> 
> static void _c2_WorkerTask(IDptr)
>    int *IDptr;
156a280,284
>    int Skip = 1;
>    int ID;
> 
>    ID = *IDptr;
>    free(IDptr);
158c286,297
< #  ifdef DEBUG /* Peter's internal debugging */
---
> 
> #  ifdef _C2_DBGR_
>    WrkrEnv[ID].pid = getpid();	/*  associate pid with env entries */
>    if (setjmp(WrkrEnv[ID].env) != 0){
>       if (_c2_debugsignals)
> 	  printf("workerTask %d: Returned from interrupt\n", ID);
>    }
>    _c2_sig_install(_c2_inthandler);
> #  endif/* _C2_DBGR_ */
> 
> 
> #  ifdef DEBUG  /* Peter's debugging stuff for worker tasks*/
162,165d300
<    while (!_c2_Terminated) {
< #     ifdef _C2_DBGR_
<             if (_c2_GlobalState == _c2_STOPPED)  break; /* go look at news */
< #     endif
166a302,309
>       /*      if (TotalCount % 50000 == 0) {
> 	      printf("Worker %d: Total %d, Idle %d, Runs %d, Reruns %d\n",
> 	      ID, TotalCount, IdleCount, RunCount, ReRunCount);
> 	      fflush(stdout);
> 	      } */
> 
> 
>    while (!_c2_Terminated) {
168,173c311,312
< #     ifdef DEBUG
<         if (TotalCount % 50000 == 0) {
< 	   printf("Worker %d: Total %d, Idle %d, Runs %d, Reruns %d\n",
< 		  ID, TotalCount, IdleCount, RunCount, ReRunCount);
< 	   fflush(stdout);
< 	} 
---
> #     ifdef _C2_DBGR_
>       if (_c2_GlobalState == _c2_STOPPED)  continue; 
177d315
< 
179c317
< #     ifdef _C2_DBGR_
---
> #       ifdef _C2_DBGR_
181a320
> #       endif
183c322,326
< 	    break;  /* go look at news from the instrumentation */
---
> 	    Skip <<= 1;
> 	    if (Skip > 1024) Skip = 32;
> 	    _c2_spin(Skip); 
> 	    continue;		/* nothing to do */
> #       ifdef _C2_DBGR_
185,188c328
< #     else  /* not _C2_DBGR_ */
< 	 IdleCount++;
< 	 continue;  /* nothing to do */
< #     endif /* _C2_DBGR_ */
---
> #       endif
190c330
< 
---
>       Skip = 32;
193c333
< #     ifdef DEBUG
---
> #   ifdef DEBUG
195,196c335
<       fflush(stdout);
< 
---
>     fflush(stdout);
201a341,348
> #ifdef DEBUG
>       printf ("foo\n");
> #endif
>       LockAcquire(&(NodeToRun->QueueLock));
> #ifdef DEBUG
>       printf ("foo\n");
> #endif
> 
203,206d349
< #      ifdef _C2_DBGR_
<        case _c2_ONDBGQ:         /* debugger will run it later on */
<          break;
< #      endif
207a351,353
> #ifdef DEBUG
>       printf ("foo\n");
> #endif
208a355,360
> 	 LockRelease(&(NodeToRun->QueueLock));
> 	 break;
> 
> #      ifdef _C2_DBGR_
>        case _c2_ONDBGQ:		/* debugger will run it later on */
> 	 LockRelease(&(NodeToRun->QueueLock));
209a362,363
> #      endif
> 
214a369
> 	 LockRelease(&(NodeToRun->QueueLock));
216,217c371,372
<            printf("Worker %d Re-running a %d\n", ID, NodeToRun->UID);
<            fflush(stdout);
---
> 	 printf("Worker %d Re-running a %d\n", ID, NodeToRun->UID);
> 	 fflush(stdout);
220a376,378
> #ifdef DEBUG
>       printf ("foo\n");
> #endif
226a385
> 	 LockRelease(&(NodeToRun->QueueLock));
231,235c390,409
<    if (_c2_Terminated) {
<       printf("Worker %d: Total %d, Idle %d, Runs %d, Reruns %d\n",
< 	     ID, TotalCount, IdleCount, RunCount, ReRunCount);
<       printf("Worker %d terminates\n", ID);
<    }
---
>    printf("Worker %d: Total %d, Idle %d, Runs %d, Reruns %d\n",
> 	  ID, TotalCount, IdleCount, RunCount, ReRunCount);
>    printf("Worker %d terminates\n", ID);
> }
> 
>   /* Wait for workers (and the debugger when invoked)*/
> 
> void _c2_WaitforThreads()
> {
>    int i;
>    for (i=0; i<numProcessors; i++)
>      ThreadJoin(WorkerList[i]);
> 
> #ifdef DEBUG
>    printf("Workers have all joined.\n");
>    printf("_c2_Terminated = %d\n", _c2_Terminated);
> #endif
> 
>    ProgramDone();
> 
237a412,414
> 
> 
> 
239c416
<    _c2_NodeBase *InitNode;
---
>   _c2_NodeBase *InitNode;
240a418
>    int i;
241a420,426
> 
>    if (numProcessors > MAXWORKERS) {
>       fprintf(stderr, "** Only %d workers are allowed\n", MAXWORKERS);
>       exit(1);
>    }
> 
>    LockInit(&RQLock);
247c432,433
<    _c2_EnQueue(InitNode);
---
>       _c2_EnQueue(InitNode);
> 
249c435,446
<    _c2_WorkerTask(0);
---
>    /* Start the workers; if debugger is installed then  */
>    /* reserve one processor for the debugger; indicated by nd = 1*/
> 
>       for (i= 0; i< numProcessors; i++) {
> 	int *iptr;
> 	iptr = (int *) malloc(sizeof(int));
> 	*iptr = i;
> 	WorkerList[i] = ThreadStart(_c2_WorkerTask, JOIN, "worker", 1, iptr);
>       }
> 
> 
>    printf("started %d workers...\n", numProcessors);
252,253c449
<    printf("Workers have all joined.\n");
<    printf("_c2_Terminated = %d\n", _c2_Terminated);
---
>    printf("Workers have all started\n");
255c451
< 
---
>      _c2_WaitforThreads();
258d453
< #ifdef _C2_DBGR_
260a456,457
> #ifdef _C2_DBGR_
> 
266,268d462
<    _c2_saveInitNode(InitNode);
<    _c2_ScopeInit(InitNode->MyGraph);
<    _c2_Terminated = 0;
270,271c464,465
<    _c2_dbginstalled = 1;        /* install one debugger task also  */
<    _c2_initWrkrDbg(0);
---
>    int i;
>    int debuggerid;
273,275c467,477
<    _c2_DebuggerTask(0, argc, argv); /*  0, because debugger and worker will be running 
<                                      on the same process*/
< }
---
>    if (numProcessors < 2) {
>       fprintf(stderr, "at least 2 processors needed for c2udbg\n");
>       fprintf(stderr, " try running %s with -n# option\n", argv[0]);
>       exit(1);
> 
>    } else if (numProcessors > MAXWORKERS) {
>       fprintf(stderr, "** Only %d workers are allowed\n", MAXWORKERS);
>       exit(1);
>    }
>    _c2_saveInitNode(InitNode);
>    _c2_ScopeInit(InitNode->MyGraph);
276a479,490
>    debuggerid = numProcessors -1;
>    /* workers' ids range from  0..(debuggerid-1) */
>    _c2_initWrkrs(debuggerid-1);
> 
>    printf ("creating workerlist[%d]...\n", debuggerid);
> 
>    WorkerList[debuggerid] = ThreadStart(_c2_DebuggerTask, JOIN,
> 				 "worker",3,  debuggerid, argc, argv);    
>    LockInit(&RQLock);
>    Head = 0;
>    FreeList = 0;
>    _c2_Terminated = 0;
278,281c492,507
< void _c2_emptyRdyQ()
< {
<    while(_c2_PopNode())
<      ;
---
>    /* Start the workers; The number of workers is one less 
>     * than the number of
>     * of processors. One processor is reserved for the debugger
>     */
>    for (i= 0; i< numProcessors - 1; i++) {
> 	int *iptr;
> 	iptr = (int *) malloc(sizeof(int));
> 	*iptr = i;
>        WorkerList[i] = ThreadStart(_c2_WorkerTask, JOIN, "worker", 1, iptr);
>     }
> 
> #  ifdef DEBUG
>       printf("Workers have all joined.\n");
>       printf("_c2_Terminated = %d\n", _c2_Terminated);
> #  endif
>    _c2_WaitforThreads();
283a510
> #endif /* _C2_DBGR_ */
285d511
< /* Dummies for compatiblity with FastThreads */
287,290d512
< void _c2_KillWorkers()
< {
<    int i;
< }
292,295d513
< void _c2_inthandler()
< {
<    int i;
< }
297,300d514
< void _c2_ChldHndler()
< { 
<    int i;
< }
302d515
< #endif
5a6,7
> #include "arch-specific.h"
> 
20a23,27
>          /* AbEnd reasons */
> 
> #define _c2_CREPTWICE 1
> #define _c2_RMFROMEMPTY 2
> 
27,32d33
< #define _c2_ONDBGQ 5     /* node is stopped and on the debug Q */
< 
<          /* AbEnd reasons */
< 
< #define _c2_CREPTWICE 1
< #define _c2_RMFROMEMPTY 2
35,36c36,39
<    /* runs the debugger task after the initialization of runtime system */
< void _c2_RunDebugger(/* _c2_NodeBase *InitNode, int argc, char **argv */);
---
> #define _c2_ONDBGQ 5     /* node is stopped and on the debug Q */
> 
> /* Instead of running the workers, run the debugger first */
> void _c2_RunDebugger(/*_c2_NodeBase *InitNode, int argc, char **argv */);
38c41
<    /* empty ready q in preparation for a new run by the debugger */
---
> /* empty the queue for a new run */
41c44,47
<    /* Dummy routines to provide compatiblity with sequent runtime*/
---
> /* to handle sigsegv that can not be handled in sequent */
> void _c2_ChldHndler();
> 
> /* Kill all the workers on exit from the debugger */
42a49,51
> 
> /* handle the interrupt in c2dbgamin.c */
> 
44c53
< void _c2_ChldHndler();
---
> 
46a56,59
> 
> 
> 
> 
